package com.sgb.kjwl.view.ui.adapter.self;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import androidx.core.util.Pair;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemCarinfoBinding;
import com.sgb.kjwl.model.entity.self.CarListEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.view.ui.activity.self.AddCarInfoActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class CarInfoAdapter extends BaseRecycleAdapter<CarListEntity> {


    public CarInfoAdapter(Context context, List<CarListEntity> datas) {
        super(context, R.layout.item_carinfo, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, CarListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemCarinfoBinding binding = (ItemCarinfoBinding) holder.getmBinding();
        //是否已完善车辆信息
        if (entity.getIsComplete() != null && entity.getIsComplete() == 1) {
            binding.tvItemCarInfo.setVisibility(View.VISIBLE);
            binding.llItemCarComplete.setVisibility(View.GONE);
        } else {
            binding.tvItemCarInfo.setVisibility(View.GONE);
            binding.llItemCarComplete.setVisibility(View.VISIBLE);
        }
        //车辆信息
        StringBuilder builder = new StringBuilder();
        //车型
        if (!TextUtils.isEmpty(entity.getCarTypeName())) {
            builder.append(" ").append(entity.getCarTypeName());
        }
        //车长
        if (!TextUtils.isEmpty(entity.getCarLenName())) {
            builder.append(" 车长").append(entity.getCarLenName());
        }
        //栏高
        if (!TextUtils.isEmpty(entity.getHeightHurdle())) {
            builder.append(" 栏高").append(entity.getHeightHurdle());
        }
        //载重
        if (!TextUtils.isEmpty(entity.getWeight())) {
            builder.append(" 载重").append(entity.getWeight());
        }
        if (builder.length() > 0) {
            binding.tvItemCarInfo.setText(builder.substring(1));
        }
        //车辆状态
        if (entity.getStatus() == 1 && entity.getState() == 0) {
            binding.ivItemCarStatus.setImageResource(R.mipmap.img_status_downaway);
        } else {
            switch (entity.getStatus()) {
                case 0:
                    binding.ivItemCarStatus.setImageResource(R.mipmap.img_status_verify);
                    break;
                case 1:
                    binding.ivItemCarStatus.setImageResource(R.mipmap.img_status_pass);
                    break;
                case 2:
                    binding.ivItemCarStatus.setImageResource(R.mipmap.img_status_fail);
                    break;
            }
        }
        //完善信息
        binding.tvItemCarComplete.setOnClickListener(v -> ActivityJump.jumpToActivity(context, AddCarInfoActivity.class, Pair.create("carNo", entity.getNo()), Pair.create("carId", entity.getId())));
    }
}
